<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px">
            <el-form-item label="指标名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入指标名称" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleQuery">搜索</el-button>
                <el-button plain @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <div class="button">
            <el-button type="primary" @click="handleAdd">新建</el-button>
            <el-button type="primary" @click="handleDelete">删除</el-button>
        </div>

        <el-table v-loading="loading" :data="dataList" stripe row-key="id" ref="multipleTable" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
            <el-table-column label="指标名称" align="center" prop="name" />
            <el-table-column label="评分内容" align="center" prop="remark" />
            <el-table-column label="系统评分" align="center" prop="isSystem">
                <template #default="scope">
                    <span v-if="scope.row.isSystem=='0'">否</span>
                    <span v-else>是</span>
                    <span></span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button type="text" @click="handleDetil(scope.row)">查看</el-button>
                    <el-button type="text" @click="handleUpdate(scope.row)">修改</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows" @pagination="getList" />

        <el-dialog title="查看三级指标" v-model="open" width="800px" append-to-body>
            <p class="mt15"></p>
            <el-form :model="form" label-width="120px">
                <el-row>
                    <el-col :span="14">
				        <el-form-item label="指标名称" prop="name">
					        <el-input v-model="form.name" placeholder="请输入指标名称，尽量简短" disabled/>
				        </el-form-item>
			        </el-col>
                    <el-col>
			            <el-form-item label="评分内容" prop="remark">
			            	<el-input v-model="form.remark" type="textarea" maxlength="1000" disabled
			            		show-word-limit :autosize="{ minRows: 10, maxRows: 15 }" placeholder="请输入评分内容描述" />
			            </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="系统评分" prop="isSystem">
                            <el-input type="hidden" />
			        	    {{ form.isSystem&&form.isSystem=='1'?'是':'否' }}
			            </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button plain @click="open=false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup name="threeLevelIndexLibraryManage">
import {getThreeLevelIndexList, detailThreeLevelIndexList, deleteThreeLevelIndexList} from '@/api/workEvaluation/evaluationStandardSetup/threeLevelIndexLibraryManage.js'
import { useRouter } from 'vue-router';
const { proxy } = getCurrentInstance();
const loading = ref(false);
const total = ref(0);
const multiple = ref();
const ids = ref([]);
const router = useRouter();
const dataList = ref([]);
const queryParams = ref({
    page:1,
    rows:10,
    name:undefined
})
const optionData = ref([]);
const form = ref({})
const open = ref(false);


// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  multiple.value = !selection.length;
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.page = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}
// 添加按钮
const handleAdd = ()=>{
    router.push({
        path:'/workEvaluation/evaluationStandardSetup/addThreeLevelIndex',
        query:{
            metaTitle:'新建三级指标',
        }
    })
}
// 获取详情
const detail = (id)=>{
    detailThreeLevelIndexList({id:id}).then(res=>{
        form.value = res.data;
        open.value = true;
    })
}
// 查看按钮
const handleDetil = (row)=>{
    detail(row.id)
}
// 修改按钮
const handleUpdate = (row)=>{
    router.push({
        path:'/workEvaluation/evaluationStandardSetup/addThreeLevelIndex',
        query:{
            metaTitle:'修改三级指标',
            id:row.id
        }
    })
}
// 删除按钮
const handleDelete = ()=>{
    const id = ids.value;
    proxy.$modal.confirm('是否确认删除勾选的数据项？').then(function() {
    return deleteThreeLevelIndexList({id:id.join(',')});
  }).then(() => {
    getList();
    proxy.$refs.multipleTable.clearSelection() 
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}
const getList =()=> {
    loading.value = true;
    getThreeLevelIndexList(queryParams.value).then(response => {
        dataList.value = response.data.list?response.data.list:[];
        total.value = response.data.total;
        loading.value = false;
    }).catch(err=>{
        loading.value = false;
        dataList.value = [];
        total.value = 0;
    });
}
onMounted(()=>{
    getList();
})
</script>

<style lang="scss" scoped>
.button{
    margin: 2px 0 20px;
}
</style>